package br.urca.impl;

import java.util.List;

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;

import br.urca.dao.CargoDAO;
import br.urca.model.Cargo;

@Transactional
public class JPACargoDAO implements CargoDAO {
	
	private EntityManager manager;
	
	public JPACargoDAO() {
		this(null);
	}
	
	@Inject
	public JPACargoDAO(EntityManager manager) {
		this.manager = manager;
	}

	@Override
	public List<Cargo> todos() {
		return this.manager.createQuery("SELECT c FROM Cargo c", Cargo.class)
				.getResultList();
	}

	@Override
	public Cargo buscarPorId(short id) {
		return this.manager.createQuery("SELECT c FROM Cargo c "
				+ "WHERE c.id = :id ", Cargo.class)
				.setParameter("id", id)
				.getSingleResult();
	}

}
